home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / term-source.lha / termConfig.c < prev    next >
C/C++ Source or Header  |  1995-06-19  |  65KB  |  2,790 lines

  1. /*
  2. **    termConfig.c
  3. **
  4. **    Configuration processing routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Reset routine function pointer. */
  13.  
  14. typedef VOID        (* RESET)(APTR,STRPTR);
  15.  
  16.     /* Local routines. */
  17.  
  18. STATIC BYTE        ReadSerialPrefs(struct SerialPrefs *Prefs);
  19.  
  20. STATIC VOID        ResetSerialConfig(struct SerialSettings *SerialConfig);
  21. STATIC VOID        ResetModem(struct ModemSettings *ModemConfig);
  22. STATIC VOID        ResetScreen(struct ScreenSettings *ScreenConfig);
  23. STATIC VOID        ResetTerminal(struct TerminalSettings *TerminalConfig);
  24. STATIC VOID        ResetEmulation(struct EmulationSettings *EmulationConfig);
  25. STATIC VOID        ResetClip(struct ClipSettings *ClipConfig);
  26. STATIC VOID        ResetCapture(struct CaptureSettings *CaptureConfig);
  27. STATIC VOID        ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer);
  28. STATIC VOID        ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer);
  29. STATIC VOID        ResetMisc(struct MiscSettings *MiscConfig);
  30. STATIC VOID        ResetCommand(struct CommandSettings *CommandConfig);
  31. STATIC VOID        ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib);
  32.  
  33. STATIC BYTE        WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password);
  34. STATIC BYTE        WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password);
  35. STATIC UBYTE        IsConfigChunk(ULONG ID);
  36. STATIC BYTE        ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password);
  37.  
  38. STATIC UWORD SizeTable[] =
  39. {
  40.     sizeof(struct SerialSettings),
  41.     sizeof(struct ModemSettings),
  42.     sizeof(struct CommandSettings),
  43.     sizeof(struct ScreenSettings),
  44.     sizeof(struct TerminalSettings),
  45.     sizeof(struct PathSettings),
  46.     sizeof(struct MiscSettings),
  47.     sizeof(struct ClipSettings),
  48.     sizeof(struct CaptureSettings),
  49.     sizeof(struct FileSettings),
  50.     sizeof(struct EmulationSettings),
  51.     sizeof(struct TransferSettings)
  52. };
  53.  
  54. STATIC RESET ResetTable[] =
  55. {
  56.     (RESET)ResetSerialConfig,
  57.     (RESET)ResetModem,
  58.     (RESET)ResetCommand,
  59.     (RESET)ResetScreen,
  60.     (RESET)ResetTerminal,
  61.     ResetPath,
  62.     (RESET)ResetMisc,
  63.     (RESET)ResetClip,
  64.     (RESET)ResetCapture,
  65.     ResetFile,
  66.     (RESET)ResetEmulation,
  67.     ResetTransfer
  68. };
  69.  
  70. STATIC ULONG TypeTable[] =
  71. {
  72.     ID_SERL,
  73.     ID_MODM,
  74.     ID_COMD,
  75.     ID_SCRN,
  76.     ID_TRML,
  77.     ID_PATH,
  78.     ID_MISC,
  79.     ID_CLIP,
  80.     ID_CPTR,
  81.     ID_FILE,
  82.     ID_EMLN,
  83.     ID_XFER
  84. };
  85.  
  86. #define NUM_STOPS (sizeof(Stops) / (2 * sizeof(ULONG)))
  87.  
  88. STATIC LONG Stops[] =
  89. {
  90.     ID_TERM,ID_CAT,
  91.     ID_TERM,ID_VERS,
  92.     ID_TERM,ID_DIAL,
  93.     ID_TERM,ID_DATE,
  94.     ID_TERM,ID_PHON,
  95.     ID_TERM,ID_PSWD,
  96.  
  97.     ID_TERM,ID_SERL,
  98.     ID_TERM,ID_MODM,
  99.     ID_TERM,ID_COMD,
  100.     ID_TERM,ID_SCRN,
  101.     ID_TERM,ID_TRML,
  102.     ID_TERM,ID_PATH,
  103.     ID_TERM,ID_MISC,
  104.     ID_TERM,ID_CLIP,
  105.     ID_TERM,ID_CPTR,
  106.     ID_TERM,ID_FILE,
  107.     ID_TERM,ID_EMLN,
  108.     ID_TERM,ID_XFER,
  109.     ID_TERM,ID_WINF
  110. };
  111.  
  112. enum    {    CR_IGNORE,CR_ASCR,CR_ASCRLF };
  113. enum    {    LF_IGNORE,LF_ASLF,LF_ASLFCR };
  114.  
  115. VOID __regargs
  116. FinalFix(struct Configuration *Config,BOOLEAN IsPhonebook,LONG Version,LONG Revision)
  117. {
  118.     if(Config)
  119.     {
  120.         if(Version < 4 || (Version == 4 && Revision < 3))
  121.         {
  122.             if(Config -> TransferConfig && Config -> MiscConfig)
  123.             {
  124.                 Config -> TransferConfig -> OverridePath    = Config -> MiscConfig -> OverridePath;
  125.                 Config -> TransferConfig -> SetArchivedBit    = Config -> MiscConfig -> SetArchivedBit;
  126.                 Config -> TransferConfig -> IdentifyFiles    = Config -> MiscConfig -> IdentifyFiles;
  127.                 Config -> TransferConfig -> TransferIcons    = Config -> MiscConfig -> TransferIcons;
  128.                 Config -> TransferConfig -> PerfMeter        = Config -> MiscConfig -> PerfMeter;
  129.                 Config -> TransferConfig -> HideUploadIcon    = Config -> MiscConfig -> HideUploadIcon;
  130.             }
  131.         }
  132.  
  133.         if(Version < 4 || (Version == 4 && Revision < 4))
  134.         {
  135.             if(Config -> TerminalConfig && Config -> MiscConfig)
  136.                 Config -> MiscConfig -> AlertMode = Config -> TerminalConfig -> AlertMode;
  137.         }
  138.     }
  139. }
  140.  
  141. VOID __regargs
  142. FixOldConfig(struct Configuration *Config,UBYTE ConfigChunkType,BOOLEAN IsPhonebook,LONG Version,LONG Revision)
  143. {
  144.     if((Version == 3 && Revision < 6) || Version < 3)
  145.     {
  146.         if(ConfigChunkType == PREF_CLIP)
  147.             Config -> ClipConfig -> ConvertLF = TRUE;
  148.  
  149.         if(ConfigChunkType == PREF_SERIAL)
  150.             Config -> SerialConfig -> UseOwnDevUnit = TRUE;
  151.  
  152.         if(ConfigChunkType == PREF_MISC)
  153.             Config -> MiscConfig -> ProtectiveMode = TRUE;
  154.  
  155.         if(ConfigChunkType == PREF_SCREEN)
  156.         {
  157.             Config -> ScreenConfig -> UsePens    = TRUE;
  158.             Config -> ScreenConfig -> Depth        = 0;
  159.             Config -> ScreenConfig -> PenColourMode    = 42;    // Avoid trouble
  160.         }
  161.  
  162.         if(ConfigChunkType == PREF_TRANSFER)
  163.         {
  164.             WORD i;
  165.  
  166.             Config -> TransferConfig -> MangleFileNames = FALSE;
  167.  
  168.             if(Config -> TransferConfig -> ASCIIUploadLibrary[0])
  169.                 Config -> TransferConfig -> ASCIIUploadType = XFER_XPR;
  170.  
  171.             if(Config -> TransferConfig -> ASCIIDownloadLibrary[0])
  172.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_XPR;
  173.  
  174.             if(Config -> TransferConfig -> TextUploadLibrary[0])
  175.                 Config -> TransferConfig -> TextUploadType = XFER_XPR;
  176.  
  177.             if(Config -> TransferConfig -> TextDownloadLibrary[0])
  178.                 Config -> TransferConfig -> TextDownloadType = XFER_XPR;
  179.  
  180.             if(Config -> TransferConfig -> BinaryUploadLibrary[0])
  181.                 Config -> TransferConfig -> BinaryUploadType = XFER_XPR;
  182.  
  183.             if(Config -> TransferConfig -> BinaryDownloadLibrary[0])
  184.                 Config -> TransferConfig -> BinaryDownloadType = XFER_XPR;
  185.  
  186.             for(i = 0 ; i < strlen(Config -> TransferConfig -> DefaultLibrary) - 6 ; i++)
  187.             {
  188.                 if(!Strnicmp(&Config -> TransferConfig -> DefaultLibrary[i],"zmodem",6))
  189.                 {
  190.                     strcpy(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  191.  
  192.                     Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  193.  
  194.                     break;
  195.                 }
  196.             }
  197.         }
  198.  
  199.         if(ConfigChunkType == PREF_MODEM)
  200.             Config -> ModemConfig -> AbortHangsUp = FALSE;
  201.  
  202.         if(ConfigChunkType == PREF_COMMAND && IsPhonebook)
  203.         {
  204.             strcpy(Config -> CommandConfig -> LoginMacro,Config -> CommandConfig -> StartupMacro);
  205.  
  206.             memset(Config -> CommandConfig -> StartupMacro,0,sizeof(Config -> CommandConfig -> StartupMacro));
  207.         }
  208.  
  209.         if(ConfigChunkType == PREF_CAPTURE)
  210.             Config -> CaptureConfig -> SearchHistory = 10;
  211.  
  212.         if(ConfigChunkType == PREF_EMULATION)
  213.         {
  214.             if(Config -> EmulationConfig -> DestructiveBackspace < 0 || Config -> EmulationConfig -> DestructiveBackspace > 2)
  215.                 Config -> EmulationConfig -> DestructiveBackspace = 1;
  216.         }
  217.     }
  218.  
  219.     if((Version == 4 && Revision < 1) || Version < 4)
  220.     {
  221.         if(ConfigChunkType == PREF_CLIP)
  222.             Config -> ClipConfig -> ConvertLF = TRUE;
  223.  
  224.         if(ConfigChunkType == PREF_SERIAL)
  225.         {
  226.             Config -> SerialConfig -> xONxOFF    = FALSE;
  227.             Config -> SerialConfig -> PassThrough    = TRUE;
  228.         }
  229.  
  230.         if(ConfigChunkType == PREF_MISC)
  231.             Config -> MiscConfig -> ProtectiveMode = TRUE;
  232.  
  233.         if(ConfigChunkType == PREF_MODEM)
  234.         {
  235.             Config -> ModemConfig -> RedialDelay    = (Config -> ModemConfig -> RedialDelay / 6) * 60 + (Config -> ModemConfig -> RedialDelay % 6) * 10;
  236.             Config -> ModemConfig -> TimeToConnect    = (Config -> ModemConfig -> TimeToConnect / 6) * 60 + (Config -> ModemConfig -> TimeToConnect % 6) * 10;
  237.             Config -> ModemConfig -> VerboseDialing    = FALSE;
  238.         }
  239.  
  240.         if(ConfigChunkType == PREF_TERMINAL)
  241.         {
  242.             switch(Config -> TerminalConfig -> SendCR)
  243.             {
  244.                 case CR_IGNORE:
  245.  
  246.                     Config -> TerminalConfig -> SendCR = EOL_IGNORE;
  247.                     break;
  248.  
  249.                 case CR_ASCR:
  250.  
  251.                     Config -> TerminalConfig -> SendCR = EOL_CR;
  252.                     break;
  253.  
  254.                 case CR_ASCRLF:
  255.  
  256.                     Config -> TerminalConfig -> SendCR = EOL_CRLF;
  257.                     break;
  258.             }
  259.  
  260.             switch(Config -> TerminalConfig -> ReceiveCR)
  261.             {
  262.                 case CR_IGNORE:
  263.  
  264.                     Config -> TerminalConfig -> ReceiveCR = EOL_IGNORE;
  265.                     break;
  266.  
  267.                 case CR_ASCR:
  268.  
  269.                     Config -> TerminalConfig -> ReceiveCR = EOL_CR;
  270.                     break;
  271.  
  272.                 case CR_ASCRLF:
  273.  
  274.                     Config -> TerminalConfig -> ReceiveCR = EOL_CRLF;
  275.                     break;
  276.             }
  277.  
  278.             switch(Config -> TerminalConfig -> SendLF)
  279.             {
  280.                 case LF_IGNORE:
  281.  
  282.                     Config -> TerminalConfig -> SendLF = EOL_IGNORE;
  283.                     break;
  284.  
  285.                 case LF_ASLF:
  286.  
  287.                     Config -> TerminalConfig -> SendLF = EOL_LF;
  288.                     break;
  289.  
  290.                 case LF_ASLFCR:
  291.  
  292.                     Config -> TerminalConfig -> SendLF = EOL_LFCR;
  293.                     break;
  294.             }
  295.  
  296.             switch(Config -> TerminalConfig -> ReceiveLF)
  297.             {
  298.                 case LF_IGNORE:
  299.  
  300.                     Config -> TerminalConfig -> ReceiveLF = EOL_IGNORE;
  301.                     break;
  302.  
  303.                 case LF_ASLF:
  304.  
  305.                     Config -> TerminalConfig -> ReceiveLF = EOL_LF;
  306.                     break;
  307.  
  308.                 case LF_ASLFCR:
  309.  
  310.                     Config -> TerminalConfig -> ReceiveLF = EOL_LFCR;
  311.                     break;
  312.             }
  313.         }
  314.  
  315.         if(ConfigChunkType == PREF_TRANSFER)
  316.         {
  317.             WORD i;
  318.  
  319.             if(Config -> TransferConfig -> ASCIIUploadLibrary[0])
  320.                 Config -> TransferConfig -> ASCIIUploadType = XFER_XPR;
  321.  
  322.             if(Config -> TransferConfig -> ASCIIDownloadLibrary[0])
  323.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_XPR;
  324.  
  325.             if(Config -> TransferConfig -> TextUploadLibrary[0])
  326.                 Config -> TransferConfig -> TextUploadType = XFER_XPR;
  327.  
  328.             if(Config -> TransferConfig -> TextDownloadLibrary[0])
  329.                 Config -> TransferConfig -> TextDownloadType = XFER_XPR;
  330.  
  331.             if(Config -> TransferConfig -> BinaryUploadLibrary[0])
  332.                 Config -> TransferConfig -> BinaryUploadType = XFER_XPR;
  333.  
  334.             if(Config -> TransferConfig -> BinaryDownloadLibrary[0])
  335.                 Config -> TransferConfig -> BinaryDownloadType = XFER_XPR;
  336.  
  337.             for(i = 0 ; i < strlen(Config -> TransferConfig -> DefaultLibrary) - 6 ; i++)
  338.             {
  339.                 if(!Strnicmp(&Config -> TransferConfig -> DefaultLibrary[i],"zmodem",6))
  340.                 {
  341.                     strcpy(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  342.  
  343.                     Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  344.  
  345.                     break;
  346.                 }
  347.             }
  348.  
  349.             switch(Config -> TransferConfig -> SendCR)
  350.             {
  351.                 case CR_IGNORE:
  352.  
  353.                     Config -> TransferConfig -> SendCR = EOL_IGNORE;
  354.                     break;
  355.  
  356.                 case CR_ASCR:
  357.  
  358.                     Config -> TransferConfig -> SendCR = EOL_CR;
  359.                     break;
  360.  
  361.                 case CR_ASCRLF:
  362.  
  363.                     Config -> TransferConfig -> SendCR = EOL_CRLF;
  364.                     break;
  365.             }
  366.  
  367.             switch(Config -> TransferConfig -> ReceiveCR)
  368.             {
  369.                 case CR_IGNORE:
  370.  
  371.                     Config -> TransferConfig -> ReceiveCR = EOL_IGNORE;
  372.                     break;
  373.  
  374.                 case CR_ASCR:
  375.  
  376.                     Config -> TransferConfig -> ReceiveCR = EOL_CR;
  377.                     break;
  378.  
  379.                 case CR_ASCRLF:
  380.  
  381.                     Config -> TransferConfig -> ReceiveCR = EOL_CRLF;
  382.                     break;
  383.             }
  384.  
  385.             switch(Config -> TransferConfig -> SendLF)
  386.             {
  387.                 case LF_IGNORE:
  388.  
  389.                     Config -> TransferConfig -> SendLF = EOL_IGNORE;
  390.                     break;
  391.  
  392.                 case LF_ASLF:
  393.  
  394.                     Config -> TransferConfig -> SendLF = EOL_LF;
  395.                     break;
  396.  
  397.                 case LF_ASLFCR:
  398.  
  399.                     Config -> TransferConfig -> SendLF = EOL_LFCR;
  400.                     break;
  401.             }
  402.  
  403.             switch(Config -> TransferConfig -> ReceiveLF)
  404.             {
  405.                 case LF_IGNORE:
  406.  
  407.                     Config -> TransferConfig -> ReceiveLF = EOL_IGNORE;
  408.                     break;
  409.  
  410.                 case LF_ASLF:
  411.  
  412.                     Config -> TransferConfig -> ReceiveLF = EOL_LF;
  413.                     break;
  414.  
  415.                 case LF_ASLFCR:
  416.  
  417.                     Config -> TransferConfig -> ReceiveLF = EOL_LFCR;
  418.                     break;
  419.             }
  420.         }
  421.     }
  422.  
  423.     if(Version == 4 && Revision < 3)
  424.     {
  425.         if(ConfigChunkType == PREF_CLIP)
  426.             Config -> ClipConfig -> ConvertLF = TRUE;
  427.  
  428.         if(ConfigChunkType == PREF_SERIAL)
  429.         {
  430.             Config -> SerialConfig -> xONxOFF    = FALSE;
  431.             Config -> SerialConfig -> PassThrough    = TRUE;
  432.         }
  433.  
  434.         if(ConfigChunkType == PREF_MISC)
  435.             Config -> MiscConfig -> ProtectiveMode = TRUE;
  436.  
  437.         if(ConfigChunkType == PREF_TRANSFER)
  438.         {
  439.             WORD i;
  440.  
  441.             for(i = 0 ; i < strlen(Config -> TransferConfig -> DefaultLibrary) - 6 ; i++)
  442.             {
  443.                 if(!Strnicmp(&Config -> TransferConfig -> DefaultLibrary[i],"zmodem",6))
  444.                 {
  445.                     strcpy(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  446.  
  447.                     Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  448.  
  449.                     break;
  450.                 }
  451.             }
  452.  
  453.             if(Config -> TransferConfig -> ASCIIUploadLibrary[0])
  454.                 Config -> TransferConfig -> ASCIIUploadType = XFER_XPR;
  455.  
  456.             if(Config -> TransferConfig -> ASCIIDownloadLibrary[0])
  457.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_XPR;
  458.  
  459.             if(Config -> TransferConfig -> InternalASCIIUpload)
  460.                 Config -> TransferConfig -> ASCIIUploadType = XFER_INTERNAL;
  461.  
  462.             if(Config -> TransferConfig -> InternalASCIIDownload)
  463.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_INTERNAL;
  464.  
  465.             if(Config -> TransferConfig -> TextUploadLibrary[0])
  466.                 Config -> TransferConfig -> TextUploadType = XFER_XPR;
  467.  
  468.             if(Config -> TransferConfig -> TextDownloadLibrary[0])
  469.                 Config -> TransferConfig -> TextDownloadType = XFER_XPR;
  470.  
  471.             if(Config -> TransferConfig -> BinaryUploadLibrary[0])
  472.                 Config -> TransferConfig -> BinaryUploadType = XFER_XPR;
  473.  
  474.             if(Config -> TransferConfig -> BinaryDownloadLibrary[0])
  475.                 Config -> TransferConfig -> BinaryDownloadType = XFER_XPR;
  476.         }
  477.     }
  478. }
  479.  
  480. VOID __regargs
  481. FixScreenPens(struct ScreenSettings *ScreenConfig)
  482. {
  483.     WORD i,Count;
  484.  
  485.     for(Count = 0, i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  486.     {
  487.         if(ScreenConfig -> PenArray[i])
  488.             Count++;
  489.     }
  490.  
  491.     if(!Count)
  492.         ScreenConfig -> UsePens = TRUE;
  493. }
  494.  
  495.     /* ReadSerialPrefs():
  496.      *
  497.      *    Reads the default serial preferences settings.
  498.      */
  499.  
  500. STATIC BYTE
  501. ReadSerialPrefs(struct SerialPrefs *Prefs)
  502. {
  503.     struct IFFHandle    *Handle;
  504.     BYTE             Success = FALSE;
  505.     LONG             Error = 0;
  506.  
  507.         /* Allocate an IFF handle. */
  508.  
  509.     if(Handle = AllocIFF())
  510.     {
  511.             /* Open the preferences settings file. */
  512.  
  513.         if(Handle -> iff_Stream = Open("ENV:sys/serial.prefs",MODE_OLDFILE))
  514.         {
  515.                 /* Make it known as a DOS file handle. */
  516.  
  517.             InitIFFasDOS(Handle);
  518.  
  519.                 /* Open the file for reading. */
  520.  
  521.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  522.             {
  523.                     /* Stop at the `body' chunk. */
  524.  
  525.                 if(!(Error = StopChunk(Handle,ID_PREF,ID_SERL)))
  526.                 {
  527.                         /* Look for it... */
  528.  
  529.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  530.                     {
  531.                             /* Read the data. */
  532.  
  533.                         if(ReadChunkBytes(Handle,Prefs,sizeof(struct SerialPrefs)) == sizeof(struct SerialPrefs))
  534.                             Success = TRUE;
  535.                         else
  536.                             Error = IoErr();
  537.                     }
  538.                 }
  539.  
  540.                     /* Close the handle. */
  541.  
  542.                 CloseIFF(Handle);
  543.             }
  544.  
  545.                 /* Release the handle. */
  546.  
  547.             Close(Handle -> iff_Stream);
  548.         }
  549.         else
  550.             Error = IoErr();
  551.  
  552.             /* Clean up. */
  553.  
  554.         FreeIFF(Handle);
  555.     }
  556.     else
  557.         Error = ERR_NO_MEM;
  558.  
  559.     if(Error)
  560.         SetIoErr(Error);
  561.  
  562.         /* Return sucess/failure. */
  563.  
  564.     return(Success);
  565. }
  566.  
  567. STATIC VOID
  568. ResetSerialConfig(struct SerialSettings *SerialConfig)
  569. {
  570.     STATIC BYTE            SerialPrefsRead        = FALSE,
  571.                     SerialPrefsReadFailed    = FALSE;
  572.     STATIC struct SerialPrefs    SerialPrefs;
  573.  
  574.         /* The program will only try to read the preferences
  575.          * settings once; if the first access failed, no
  576.          * other accesses will be made.
  577.          */
  578.  
  579.     if(!SerialPrefsRead && !SerialPrefsReadFailed)
  580.         SerialPrefsReadFailed = ReadSerialPrefs(&SerialPrefs) ^ TRUE;
  581.  
  582.         /* Did we succeed in reading the file? */
  583.  
  584.     if(!SerialPrefsRead)
  585.     {
  586.         SerialConfig -> BaudRate        = 19200;
  587.         SerialConfig -> BitsPerChar        = 8;
  588.         SerialConfig -> Parity            = PARITY_NONE;
  589.         SerialConfig -> StopBits        = 1;
  590.         SerialConfig -> HandshakingProtocol    = HANDSHAKING_RTSCTS_DSR;
  591.         SerialConfig -> SerialBufferSize    = 32768;
  592.     }
  593.     else
  594.     {
  595.             /* Fill in the common data. */
  596.  
  597.         SerialConfig -> BaudRate        = SerialPrefs . sp_BaudRate;
  598.         SerialConfig -> SerialBufferSize    = SerialPrefs . sp_InputBuffer;
  599.         SerialConfig -> BitsPerChar        = SerialPrefs . sp_BitsPerChar;
  600.         SerialConfig -> StopBits        = SerialPrefs . sp_StopBits;
  601.  
  602.             /* Convert the handshaking mode. */
  603.  
  604.         switch(SerialPrefs . sp_InputHandshake)
  605.         {
  606.             case HSHAKE_NONE:
  607.  
  608.                 SerialConfig -> HandshakingProtocol = HANDSHAKING_NONE;
  609.  
  610.                 break;
  611.  
  612.             case HSHAKE_RTS:
  613.  
  614.                 SerialConfig -> HandshakingProtocol = HANDSHAKING_RTSCTS_DSR;
  615.  
  616.                 break;
  617.  
  618.             default:
  619.  
  620.                 SerialConfig -> HandshakingProtocol = HANDSHAKING_NONE;
  621.  
  622.                 break;
  623.         }
  624.  
  625.             /* Convert the parity settings. */
  626.  
  627.         if(SerialPrefs . sp_Parity <= PARITY_SPACE)
  628.             SerialConfig -> Parity = SerialPrefs . sp_Parity;
  629.         else
  630.             SerialConfig -> Parity = PARITY_NONE;
  631.  
  632.         SerialPrefsRead = TRUE;
  633.     }
  634.  
  635.     strcpy(SerialConfig -> SerialDevice,SERIALNAME);
  636.  
  637.     SerialConfig -> Duplex        = DUPLEX_FULL;
  638.     SerialConfig -> HighSpeed    = FALSE;
  639.     SerialConfig -> Shared        = FALSE;
  640.     SerialConfig -> BreakLength    = 250000;
  641.     SerialConfig -> UnitNumber    = 0;
  642.     SerialConfig -> StripBit8    = FALSE;
  643.     SerialConfig -> CheckCarrier    = FALSE;
  644.     SerialConfig -> xONxOFF        = FALSE;
  645.     SerialConfig -> PassThrough    = TRUE;
  646.     SerialConfig -> IgnoreCarrier    = FALSE;
  647.  
  648.     SerialConfig -> Quantum        = 256;
  649.  
  650.     SerialConfig -> UseNet        = FALSE;
  651.     SerialConfig -> NetID        = 0002;
  652.  
  653.     SerialConfig -> SatisfyODURequests = ODU_RELEASE;
  654.  
  655.     SerialConfig -> LastVersionSaved    = 0;
  656.     SerialConfig -> LastRevisionSaved    = 0;
  657.  
  658.     SerialConfig -> DirectConnection    = FALSE;
  659. }
  660.  
  661. STATIC VOID
  662. ResetModem(struct ModemSettings *ModemConfig)
  663. {
  664.     strcpy(ModemConfig -> ModemInit,    "AT\\r");
  665.     strcpy(ModemConfig -> ModemExit,    "");
  666.     strcpy(ModemConfig -> ModemHangup,    "~~~~~~~~+++~~~~~~ATH0\\r");
  667.     strcpy(ModemConfig -> DialPrefix,    "~~ATD\\w");
  668.     strcpy(ModemConfig -> DialSuffix,    "\\r");
  669.  
  670.     strcpy(ModemConfig -> NoCarrier,    "NO CARRIER");
  671.     strcpy(ModemConfig -> NoDialTone,    "NO DIALTONE");
  672.     strcpy(ModemConfig -> Connect,        "CONNECT");
  673.     strcpy(ModemConfig -> Voice,        "VOICE");
  674.     strcpy(ModemConfig -> Ring,        "RING");
  675.     strcpy(ModemConfig -> Busy,        "BUSY");
  676.     strcpy(ModemConfig -> Ok,        "OK");
  677.     strcpy(ModemConfig -> Error,        "ERROR");
  678.  
  679.     ModemConfig -> RedialDelay        = 20;
  680.     ModemConfig -> DialRetries        = 10;
  681.     ModemConfig -> DialTimeout        = 60;
  682.     ModemConfig -> ConnectAutoBaud        = FALSE;
  683.     ModemConfig -> DropDTR            = FALSE;
  684.     ModemConfig -> RedialAfterHangup    = FALSE;
  685.  
  686.     ModemConfig -> NoCarrierIsBusy        = TRUE;
  687.  
  688.     ModemConfig -> ConnectLimit        = 0;
  689.     ModemConfig -> ConnectLimitMacro[0]    = 0;
  690.  
  691.     ModemConfig -> TimeToConnect        = 0;
  692.  
  693.     ModemConfig -> VerboseDialing        = FALSE;
  694.  
  695.     ModemConfig -> DialMode            = DIALMODE_TONE;
  696.     ModemConfig -> Pad            = 0;
  697.  
  698.     ModemConfig -> InterDialDelay        = 0;
  699.     ModemConfig -> CharSendDelay        = 0;
  700. }
  701.  
  702. STATIC VOID
  703. ResetScreen(struct ScreenSettings *ScreenConfig)
  704. {
  705.     ULONG         DisplayID;
  706.     struct Screen    *PubScreen;
  707.  
  708.     if(PubScreen = LockPubScreen(NULL))
  709.     {
  710.         DisplayID = GetVPModeID(&PubScreen -> ViewPort);
  711.  
  712.         UnlockPubScreen(NULL,PubScreen);
  713.     }
  714.     else
  715.         DisplayID = DEFAULT_MONITOR_ID | HIRESLACE_KEY;
  716.  
  717.     memset(ScreenConfig,0,sizeof(struct ScreenSettings));
  718.  
  719.     ScreenConfig -> DisplayMode        = DisplayID;
  720.     ScreenConfig -> ColourMode        = COLOUR_AMIGA;
  721.     ScreenConfig -> MakeScreenPublic    = TRUE;
  722.     ScreenConfig -> ShanghaiWindows        = FALSE;
  723.     ScreenConfig -> TitleBar        = TRUE;
  724.     ScreenConfig -> StatusLine        = STATUSLINE_STANDARD;
  725.     ScreenConfig -> Blinking        = TRUE;
  726.     ScreenConfig -> FasterLayout        = TRUE;
  727.     ScreenConfig -> UseWorkbench        = FALSE;
  728.  
  729.     strcpy(ScreenConfig -> FontName,"topaz.font");
  730.     ScreenConfig -> FontHeight = 8;
  731.  
  732.     ScreenConfig -> PubScreenName[0]    = 0;
  733.     ScreenConfig -> TimeMode        = ONLINETIME_BOTH;
  734.     ScreenConfig -> UsePens            = TRUE;
  735.     ScreenConfig -> PenColourMode        = COLOUR_AMIGA;
  736.  
  737.     ScreenConfig -> DisplayWidth        = 0;
  738.     ScreenConfig -> DisplayHeight        = 0;
  739.     ScreenConfig -> OverscanType        = OSCAN_TEXT;
  740.  
  741.     ScreenConfig -> ShareScreen        = FALSE;
  742.     ScreenConfig -> SplitStatus        = FALSE;
  743.  
  744.     ScreenConfig -> UseColours96        = FALSE;
  745. }
  746.  
  747. STATIC VOID
  748. ResetTerminal(struct TerminalSettings *TerminalConfig)
  749. {
  750.     TerminalConfig -> BellMode        = BELL_AUDIBLE;
  751.     TerminalConfig -> AlertMode        = ALERT_BEEP_SCREEN;
  752.     TerminalConfig -> EmulationMode        = EMULATION_ANSIVT100;
  753.     TerminalConfig -> FontMode        = FONT_STANDARD;
  754.  
  755.     TerminalConfig -> SendCR        = EOL_CR;
  756.     TerminalConfig -> SendLF        = EOL_LF;
  757.     TerminalConfig -> ReceiveCR        = EOL_CR;
  758.     TerminalConfig -> ReceiveLF        = EOL_LF;
  759.  
  760.     TerminalConfig -> NumColumns        = 0;
  761.     TerminalConfig -> NumLines        = 0;
  762.  
  763.     TerminalConfig -> KeyMapFileName[0]    = 0;
  764.     TerminalConfig -> EmulationFileName[0]    = 0;
  765.     TerminalConfig -> BeepFileName[0]    = 0;
  766.  
  767.     strcpy(TerminalConfig -> TextFontName,"topaz.font");
  768.     TerminalConfig -> TextFontHeight = 8;
  769.  
  770.     TerminalConfig -> UseTerminalTask = FALSE;
  771.     TerminalConfig -> Pad = 0;
  772.  
  773.     strcpy(TerminalConfig -> IBMFontName,"IBM.font");
  774.     TerminalConfig -> IBMFontHeight = 8;
  775. }
  776.  
  777. STATIC VOID
  778. ResetEmulation(struct EmulationSettings *EmulationConfig)
  779. {
  780.     WORD i;
  781.  
  782.     EmulationConfig -> CursorMode        = KEYMODE_STANDARD;
  783.     EmulationConfig -> NumericMode        = KEYMODE_STANDARD;
  784.  
  785.     EmulationConfig -> NewLineMode        = FALSE;
  786.     EmulationConfig -> InsertMode        = FALSE;
  787.  
  788.     EmulationConfig -> LineWrap        = TRUE;
  789.     EmulationConfig -> CursorWrap        = FALSE;
  790.  
  791.     EmulationConfig -> FontScale        = SCALE_NORMAL;
  792.     EmulationConfig -> ScrollMode        = SCROLL_JUMP;
  793.     EmulationConfig -> DestructiveBackspace    = FALSE;
  794.     EmulationConfig -> SwapBSDelete        = FALSE;
  795.     EmulationConfig -> PrinterEnabled    = TRUE;
  796.     EmulationConfig -> AnswerBack[0]    = 0;
  797.     EmulationConfig -> CLSResetsCursor    = 0;
  798.  
  799.     EmulationConfig -> KeysLocked        = FALSE;
  800.     EmulationConfig -> MaxScroll        = 0;
  801.     EmulationConfig -> MaxJump        = 1;
  802.     EmulationConfig -> CursorLocked        = FALSE;
  803.     EmulationConfig -> FontLocked        = FALSE;
  804.     EmulationConfig -> LockWrapping        = FALSE;
  805.     EmulationConfig -> LockStyle        = FALSE;
  806.     EmulationConfig -> LockColour        = FALSE;
  807.  
  808.     EmulationConfig -> UseStandardPens    = TRUE;
  809.  
  810.     for(i = TEXTATTR_UNDERLINE ; i <= TEXTATTR_INVERSE ; i++)
  811.         EmulationConfig -> Attributes[i] = i;
  812.  
  813.     for(i = 0 ; i < 16 ; i++)
  814.         EmulationConfig -> Pens[i] = i;
  815. }
  816.  
  817. STATIC VOID
  818. ResetClip(struct ClipSettings *ClipConfig)
  819. {
  820.     ClipConfig -> ClipboardUnit    = 0;
  821.     ClipConfig -> LineDelay        = 0;
  822.     ClipConfig -> CharDelay        = 0;
  823.  
  824.     ClipConfig -> InsertPrefix[0] = 0;
  825.     strcpy(ClipConfig -> InsertSuffix,"\\r");
  826.  
  827.     ClipConfig -> LinePrompt[0]    = 0;
  828.     ClipConfig -> SendTimeout    = 0;
  829.     ClipConfig -> PacingMode    = PACE_DIRECT;
  830.     ClipConfig -> ConvertLF        = TRUE;
  831. }
  832.  
  833. STATIC VOID
  834. ResetCapture(struct CaptureSettings *CaptureConfig)
  835. {
  836.     CaptureConfig -> LogActions        = FALSE;
  837.     CaptureConfig -> LogCall        = FALSE;
  838.     CaptureConfig -> LogFileName[0]        = 0;
  839.  
  840.     CaptureConfig -> MaxBufferSize        = 0;
  841.     CaptureConfig -> BufferEnabled        = TRUE;
  842.  
  843.     CaptureConfig -> ConnectAutoCapture    = FALSE;
  844.     CaptureConfig -> CaptureFilterMode    = FILTER_BOTH;
  845.     CaptureConfig -> CapturePath[0]        = 0;
  846.  
  847.     CaptureConfig -> CallLogFileName[0]    = 0;
  848.     CaptureConfig -> BufferPath[0]        = 0;
  849.  
  850.     CaptureConfig -> AutoCaptureDate    = AUTOCAPTURE_DATE_NAME;
  851.     CaptureConfig -> SearchHistory        = 10;
  852.  
  853.     CaptureConfig -> OpenBufferWindow    = BUFFER_END;
  854.     CaptureConfig -> OpenBufferScreen    = BUFFER_TOP;
  855.     CaptureConfig -> BufferScreenPosition    = SCREEN_CENTRE;
  856.     CaptureConfig -> BufferWidth        = 80;
  857.  
  858.     CaptureConfig -> RememberBufferWindow    = FALSE;
  859.     CaptureConfig -> RememberBufferScreen    = FALSE;
  860.  
  861.     CaptureConfig -> BufferScreenMode    = INVALID_ID;
  862.  
  863.     CaptureConfig -> ConvertChars        = FALSE;
  864.     CaptureConfig -> Pad            = 0;
  865. }
  866.  
  867. STATIC VOID
  868. ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer)
  869. {
  870.     if(!PathBuffer)
  871.         PathBuffer = "TERM:config";
  872.  
  873.     strcpy(FileConfig -> ProtocolFileName,"xprzmodem.library");
  874.  
  875.     if(!LastTranslation[0])
  876.     {
  877.         strcpy(LastTranslation,PathBuffer);
  878.  
  879.         AddPart(LastTranslation,"translation.prefs",MAX_FILENAME_LENGTH);
  880.     }
  881.  
  882.     strcpy(FileConfig -> TranslationFileName,LastTranslation);
  883.  
  884.     if(!LastMacros[0])
  885.     {
  886.         strcpy(LastMacros,PathBuffer);
  887.  
  888.         AddPart(LastMacros,"functionkeys.prefs",MAX_FILENAME_LENGTH);
  889.     }
  890.  
  891.     strcpy(FileConfig -> MacroFileName,LastMacros);
  892.  
  893.     if(!LastFastMacros[0])
  894.     {
  895.         strcpy(LastFastMacros,PathBuffer);
  896.  
  897.         AddPart(LastFastMacros,"fastmacros.prefs",MAX_FILENAME_LENGTH);
  898.     }
  899.  
  900.     strcpy(FileConfig -> FastMacroFileName,LastFastMacros);
  901.  
  902.     if(!LastCursorKeys[0])
  903.     {
  904.         strcpy(LastCursorKeys,PathBuffer);
  905.  
  906.         AddPart(LastCursorKeys,"cursorkeys.prefs",MAX_FILENAME_LENGTH);
  907.     }
  908.  
  909.     strcpy(FileConfig -> CursorFileName,LastCursorKeys);
  910. }
  911.  
  912. STATIC VOID
  913. ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer)
  914. {
  915.     if(!PathBuffer)
  916.         PathBuffer = "TERM:config";
  917.  
  918.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  919.  
  920.     PathConfig -> ASCIIUploadPath[0]    = 0;
  921.     PathConfig -> ASCIIDownloadPath[0]    = 0;
  922.     PathConfig -> TextUploadPath[0]        = 0;
  923.     PathConfig -> TextDownloadPath[0]    = 0;
  924.     PathConfig -> BinaryUploadPath[0]    = 0;
  925.     PathConfig -> BinaryDownloadPath[0]    = 0;
  926.  
  927.     strcpy(PathConfig -> HelpFile,"PROGDIR:term.guide");
  928.  
  929.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  930.  
  931.     GetEnvDOS(PathConfig -> Editor,"EDITOR");
  932. }
  933.  
  934. STATIC VOID
  935. ResetMisc(struct MiscSettings *MiscConfig)
  936. {
  937.     MiscConfig -> Priority            = 1;
  938.     MiscConfig -> BackupConfig        = FALSE;
  939.  
  940.     MiscConfig -> OpenFastMacroPanel    = FALSE;
  941.     MiscConfig -> ReleaseDevice        = TRUE;
  942.  
  943.     MiscConfig -> TransferServer        = TRUE;
  944.     MiscConfig -> EmulationServer        = TRUE;
  945.  
  946.     MiscConfig -> OverridePath        = TRUE;
  947.     MiscConfig -> AutoUpload        = TRUE;
  948.     MiscConfig -> SetArchivedBit        = FALSE;
  949.     MiscConfig -> IdentifyFiles        = IDENTIFY_FILETYPE;
  950.     MiscConfig -> TransferIcons        = FALSE;
  951.     MiscConfig -> CreateIcons        = FALSE;
  952.     MiscConfig -> SimpleIO            = FALSE;
  953.     MiscConfig -> PerfMeter            = FALSE;
  954.  
  955.     MiscConfig -> IOBufferSize        = 32768;
  956.     MiscConfig -> HideUploadIcon        = FALSE;
  957.  
  958.     MiscConfig -> ProtectiveMode        = TRUE;
  959.  
  960.     MiscConfig -> AlertMode            = ALERT_BEEP_SCREEN;
  961.     MiscConfig -> RequesterMode        = REQUESTERMODE_IGNORE;
  962.     MiscConfig -> RequesterLeft        = 0;
  963.     MiscConfig -> RequesterTop        = 0;
  964.     MiscConfig -> RequesterWidth        = 0;
  965.     MiscConfig -> RequesterHeight        = 0;
  966. }
  967.  
  968. STATIC VOID
  969. ResetCommand(struct CommandSettings *CommandConfig)
  970. {
  971.     CommandConfig -> StartupMacro[0]    = 0;
  972.     CommandConfig -> LogoffMacro[0]        = 0;
  973.     CommandConfig -> LoginMacro[0]        = 0;
  974.     CommandConfig -> UploadMacro[0]        = 0;
  975.     CommandConfig -> DownloadMacro[0]    = 0;
  976. }
  977.  
  978. STATIC VOID
  979. ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib)
  980. {
  981.     WORD i;
  982.  
  983.     if(!DefaultLib)
  984.         strcpy(TransferConfig -> DefaultLibrary,"xprzmodem.library");
  985.     else
  986.         strcpy(TransferConfig -> DefaultLibrary,DefaultLib);
  987.  
  988.     for(i = 0 ; i < strlen(TransferConfig -> DefaultLibrary) - 6 ; i++)
  989.     {
  990.         if(!Strnicmp(&TransferConfig -> DefaultLibrary[i],"zmodem",6))
  991.         {
  992.             strcpy(TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  993.  
  994.             TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  995.  
  996.             break;
  997.         }
  998.     }
  999.  
  1000.     strcpy(TransferConfig -> ASCIIUploadLibrary,    "xprascii.library");
  1001.     strcpy(TransferConfig -> ASCIIDownloadLibrary,    "xprascii.library");
  1002.  
  1003.     TransferConfig -> TextUploadLibrary[0]        = 0;
  1004.     TransferConfig -> TextDownloadLibrary[0]    = 0;
  1005.  
  1006.     TransferConfig -> BinaryUploadLibrary[0]    = 0;
  1007.     TransferConfig -> BinaryDownloadLibrary[0]    = 0;
  1008.  
  1009.     TransferConfig -> InternalASCIIUpload        = FALSE;
  1010.     TransferConfig -> InternalASCIIDownload        = FALSE;
  1011.     TransferConfig -> QuietTransfer            = FALSE;
  1012.     TransferConfig -> MangleFileNames        = FALSE;
  1013.  
  1014.     TransferConfig -> LinePrompt[0]            = 0;
  1015.     TransferConfig -> SendTimeout            = 0;
  1016.     TransferConfig -> PacingMode            = PACE_DIRECT;
  1017.     TransferConfig -> StripBit8            = FALSE;
  1018.     TransferConfig -> IgnoreDataPastArnold        = TRUE;
  1019.     TransferConfig -> TerminatorChar        = 0x1A;
  1020.     TransferConfig -> SendCR            = EOL_CR;
  1021.     TransferConfig -> SendLF            = EOL_LF;
  1022.     TransferConfig -> ReceiveCR            = EOL_CR;
  1023.     TransferConfig -> ReceiveLF            = EOL_LF;
  1024.  
  1025.     TransferConfig -> ErrorNotification        = 20;
  1026.     TransferConfig -> TransferNotification        = XFERNOTIFY_ALWAYS;
  1027.  
  1028.     TransferConfig -> DefaultType            = XFER_XPR;
  1029.     TransferConfig -> ASCIIDownloadType        = XFER_XPR;
  1030.     TransferConfig -> ASCIIUploadType        = XFER_XPR;
  1031.     TransferConfig -> TextDownloadType        = XFER_DEFAULT;
  1032.     TransferConfig -> TextUploadType        = XFER_DEFAULT;
  1033.     TransferConfig -> BinaryDownloadType        = XFER_DEFAULT;
  1034.     TransferConfig -> BinaryUploadType        = XFER_DEFAULT;
  1035.  
  1036.     memset(TransferConfig -> Signatures,0,sizeof(TransferConfig -> Signatures));
  1037.  
  1038.     TransferConfig -> OverridePath            = TRUE;
  1039.     TransferConfig -> SetArchivedBit        = FALSE;
  1040.     TransferConfig -> IdentifyFiles            = IDENTIFY_FILETYPE;
  1041.     TransferConfig -> TransferIcons            = FALSE;
  1042.     TransferConfig -> PerfMeter            = FALSE;
  1043.     TransferConfig -> HideUploadIcon        = FALSE;
  1044. }
  1045.  
  1046.     /* ResetConfig():
  1047.      *
  1048.      *    Initialize configuration with default values.
  1049.      */
  1050.  
  1051. VOID __regargs
  1052. ResetConfig(struct Configuration *Config,STRPTR PathBuffer)
  1053. {
  1054.     if(!PathBuffer)
  1055.         PathBuffer = "TERM:config";
  1056.  
  1057.     ResetPath(Config -> PathConfig,PathBuffer);
  1058.     ResetFile(Config -> FileConfig,PathBuffer);
  1059.  
  1060.     ResetSerialConfig(Config -> SerialConfig);
  1061.     ResetModem(Config -> ModemConfig);
  1062.     ResetScreen(Config -> ScreenConfig);
  1063.     ResetTerminal(Config -> TerminalConfig);
  1064.     ResetEmulation(Config -> EmulationConfig);
  1065.     ResetClip(Config -> ClipConfig);
  1066.     ResetCapture(Config -> CaptureConfig);
  1067.     ResetMisc(Config -> MiscConfig);
  1068.     ResetCommand(Config -> CommandConfig);
  1069.     ResetTransfer(Config -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  1070. }
  1071.  
  1072. VOID __regargs
  1073. DeleteConfigEntry(struct Configuration *Config,BYTE Type)
  1074. {
  1075.     if(Type == PREF_ALL)
  1076.     {
  1077.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1078.             DeleteConfigEntry(Config,Type);
  1079.     }
  1080.     else
  1081.     {
  1082.         switch(Type)
  1083.         {
  1084.             case PREF_SERIAL:
  1085.  
  1086.                 if(Config -> SerialConfig)
  1087.                 {
  1088.                     FreeVecPooled(Config -> SerialConfig);
  1089.  
  1090.                     Config -> SerialConfig = NULL;
  1091.                 }
  1092.  
  1093.                 break;
  1094.  
  1095.             case PREF_MODEM:
  1096.  
  1097.                 if(Config -> ModemConfig)
  1098.                 {
  1099.                     FreeVecPooled(Config -> ModemConfig);
  1100.  
  1101.                     Config -> ModemConfig = NULL;
  1102.                 }
  1103.  
  1104.                 break;
  1105.  
  1106.             case PREF_COMMAND:
  1107.  
  1108.                 if(Config -> CommandConfig)
  1109.                 {
  1110.                     FreeVecPooled(Config -> CommandConfig);
  1111.  
  1112.                     Config -> CommandConfig = NULL;
  1113.                 }
  1114.  
  1115.                 break;
  1116.  
  1117.             case PREF_SCREEN:
  1118.  
  1119.                 if(Config -> ScreenConfig)
  1120.                 {
  1121.                     FreeVecPooled(Config -> ScreenConfig);
  1122.  
  1123.                     Config -> ScreenConfig = NULL;
  1124.                 }
  1125.  
  1126.                 break;
  1127.  
  1128.             case PREF_TERMINAL:
  1129.  
  1130.                 if(Config -> TerminalConfig)
  1131.                 {
  1132.                     FreeVecPooled(Config -> TerminalConfig);
  1133.  
  1134.                     Config -> TerminalConfig = NULL;
  1135.                 }
  1136.  
  1137.                 break;
  1138.  
  1139.             case PREF_PATH:
  1140.  
  1141.                 if(Config -> PathConfig)
  1142.                 {
  1143.                     FreeVecPooled(Config -> PathConfig);
  1144.  
  1145.                     Config -> PathConfig = NULL;
  1146.                 }
  1147.  
  1148.                 break;
  1149.  
  1150.             case PREF_MISC:
  1151.  
  1152.                 if(Config -> MiscConfig)
  1153.                 {
  1154.                     FreeVecPooled(Config -> MiscConfig);
  1155.  
  1156.                     Config -> MiscConfig = NULL;
  1157.                 }
  1158.  
  1159.                 break;
  1160.  
  1161.             case PREF_CLIP:
  1162.  
  1163.                 if(Config -> ClipConfig)
  1164.                 {
  1165.                     FreeVecPooled(Config -> ClipConfig);
  1166.  
  1167.                     Config -> ClipConfig = NULL;
  1168.                 }
  1169.  
  1170.                 break;
  1171.  
  1172.             case PREF_CAPTURE:
  1173.  
  1174.                 if(Config -> CaptureConfig)
  1175.                 {
  1176.                     FreeVecPooled(Config -> CaptureConfig);
  1177.  
  1178.                     Config -> CaptureConfig = NULL;
  1179.                 }
  1180.  
  1181.                 break;
  1182.  
  1183.             case PREF_FILE:
  1184.  
  1185.                 if(Config -> FileConfig)
  1186.                 {
  1187.                     FreeVecPooled(Config -> FileConfig);
  1188.  
  1189.                     Config -> FileConfig = NULL;
  1190.                 }
  1191.  
  1192.                 break;
  1193.  
  1194.             case PREF_EMULATION:
  1195.  
  1196.                 if(Config -> EmulationConfig)
  1197.                 {
  1198.                     FreeVecPooled(Config -> EmulationConfig);
  1199.  
  1200.                     Config -> EmulationConfig = NULL;
  1201.                 }
  1202.  
  1203.                 break;
  1204.  
  1205.             case PREF_TRANSFER:
  1206.  
  1207.                 if(Config -> TransferConfig)
  1208.                 {
  1209.                     FreeVecPooled(Config -> TransferConfig);
  1210.  
  1211.                     Config -> TransferConfig = NULL;
  1212.                 }
  1213.  
  1214.                 break;
  1215.         }
  1216.     }
  1217. }
  1218.  
  1219. VOID __regargs
  1220. ResetConfigEntry(struct Configuration *Configuration,BYTE Type,BYTE Default)
  1221. {
  1222.     if(Type == PREF_ALL)
  1223.     {
  1224.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1225.             ResetConfigEntry(Configuration,Type,Default);
  1226.     }
  1227.     else
  1228.     {
  1229.         switch(Type)
  1230.         {
  1231.             case PREF_SERIAL:
  1232.  
  1233.                 if(Default || !Config -> SerialConfig)
  1234.                     ResetSerialConfig(Configuration -> SerialConfig);
  1235.                 else
  1236.                     memcpy(Configuration -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  1237.  
  1238.                 break;
  1239.  
  1240.             case PREF_MODEM:
  1241.  
  1242.                 if(Default || !Config -> ModemConfig)
  1243.                     ResetModem(Configuration -> ModemConfig);
  1244.                 else
  1245.                     memcpy(Configuration -> ModemConfig,Config -> ModemConfig,sizeof(struct ModemSettings));
  1246.  
  1247.                 break;
  1248.  
  1249.             case PREF_COMMAND:
  1250.  
  1251.                 if(Default || !Config -> CommandConfig)
  1252.                     ResetCommand(Configuration -> CommandConfig);
  1253.                 else
  1254.                     memcpy(Configuration -> CommandConfig,Config -> CommandConfig,sizeof(struct CommandSettings));
  1255.  
  1256.                 break;
  1257.  
  1258.             case PREF_SCREEN:
  1259.  
  1260.                 if(Default || !Config -> ScreenConfig)
  1261.                     ResetScreen(Configuration -> ScreenConfig);
  1262.                 else
  1263.                     memcpy(Configuration -> ScreenConfig,Config -> ScreenConfig,sizeof(struct ScreenSettings));
  1264.  
  1265.                 FixScreenPens(Configuration -> ScreenConfig);
  1266.  
  1267.                 break;
  1268.  
  1269.             case PREF_TERMINAL:
  1270.  
  1271.                 if(Default || !Config -> TerminalConfig)
  1272.                     ResetTerminal(Configuration -> TerminalConfig);
  1273.                 else
  1274.                     memcpy(Configuration -> TerminalConfig,Config -> TerminalConfig,sizeof(struct TerminalSettings));
  1275.  
  1276.                 break;
  1277.  
  1278.             case PREF_PATH:
  1279.  
  1280.                 if(Default || !Config -> PathConfig)
  1281.                     ResetPath(Configuration -> PathConfig,NULL);
  1282.                 else
  1283.                     memcpy(Configuration -> PathConfig,Config -> PathConfig,sizeof(struct PathSettings));
  1284.  
  1285.                 break;
  1286.  
  1287.             case PREF_MISC:
  1288.  
  1289.                 if(Default || !Config -> MiscConfig)
  1290.                     ResetMisc(Configuration -> MiscConfig);
  1291.                 else
  1292.                     memcpy(Configuration -> MiscConfig,Config -> MiscConfig,sizeof(struct MiscSettings));
  1293.  
  1294.                 break;
  1295.  
  1296.             case PREF_CLIP:
  1297.  
  1298.                 if(Default || !Config -> ClipConfig)
  1299.                     ResetClip(Configuration -> ClipConfig);
  1300.                 else
  1301.                     memcpy(Configuration -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings));
  1302.  
  1303.                 break;
  1304.  
  1305.             case PREF_CAPTURE:
  1306.  
  1307.                 if(Default || !Config -> CaptureConfig)
  1308.                     ResetCapture(Configuration -> CaptureConfig);
  1309.                 else
  1310.                     memcpy(Configuration -> CaptureConfig,Config -> CaptureConfig,sizeof(struct CaptureSettings));
  1311.  
  1312.                 break;
  1313.  
  1314.             case PREF_FILE:
  1315.  
  1316.                 if(Default || !Config -> FileConfig)
  1317.                     ResetFile(Configuration -> FileConfig,NULL);
  1318.                 else
  1319.                     memcpy(Configuration -> FileConfig,Config -> FileConfig,sizeof(struct FileSettings));
  1320.  
  1321.                 break;
  1322.  
  1323.             case PREF_EMULATION:
  1324.  
  1325.                 if(Default || !Config -> EmulationConfig)
  1326.                     ResetEmulation(Configuration -> EmulationConfig);
  1327.                 else
  1328.                     memcpy(Configuration -> EmulationConfig,Config -> EmulationConfig,sizeof(struct EmulationSettings));
  1329.  
  1330.                 break;
  1331.  
  1332.             case PREF_TRANSFER:
  1333.  
  1334.                 if(Default || !Config -> TransferConfig)
  1335.                     ResetTransfer(Configuration -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  1336.                 else
  1337.                     memcpy(Configuration -> TransferConfig,Config -> TransferConfig,sizeof(struct TransferSettings));
  1338.  
  1339.                 break;
  1340.         }
  1341.     }
  1342. }
  1343.  
  1344. APTR __regargs
  1345. GetConfigEntry(struct Configuration *Config,BYTE Type)
  1346. {
  1347.     switch(Type)
  1348.     {
  1349.         case PREF_SERIAL:
  1350.  
  1351.             return(Config -> SerialConfig);
  1352.  
  1353.         case PREF_MODEM:
  1354.  
  1355.             return(Config -> ModemConfig);
  1356.  
  1357.         case PREF_COMMAND:
  1358.  
  1359.             return(Config -> CommandConfig);
  1360.  
  1361.         case PREF_SCREEN:
  1362.  
  1363.             return(Config -> ScreenConfig);
  1364.  
  1365.         case PREF_TERMINAL:
  1366.  
  1367.             return(Config -> TerminalConfig);
  1368.  
  1369.         case PREF_PATH:
  1370.  
  1371.             return(Config -> PathConfig);
  1372.  
  1373.         case PREF_MISC:
  1374.  
  1375.             return(Config -> MiscConfig);
  1376.  
  1377.         case PREF_CLIP:
  1378.  
  1379.             return(Config -> ClipConfig);
  1380.  
  1381.         case PREF_CAPTURE:
  1382.  
  1383.             return(Config -> CaptureConfig);
  1384.  
  1385.         case PREF_FILE:
  1386.  
  1387.             return(Config -> FileConfig);
  1388.  
  1389.         case PREF_EMULATION:
  1390.  
  1391.             return(Config -> EmulationConfig);
  1392.  
  1393.         case PREF_TRANSFER:
  1394.  
  1395.             return(Config -> TransferConfig);
  1396.  
  1397.         default:
  1398.  
  1399.             return(NULL);
  1400.     }
  1401. }
  1402.  
  1403. BYTE __regargs
  1404. CreateConfigEntry(struct Configuration *Config,BYTE Type)
  1405. {
  1406.     if(Type == PREF_ALL)
  1407.     {
  1408.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1409.         {
  1410.             if(!CreateConfigEntry(Config,Type))
  1411.             {
  1412.                 DeleteConfigEntry(Config,PREF_ALL);
  1413.  
  1414.                 return(FALSE);
  1415.             }
  1416.         }
  1417.  
  1418.         return(TRUE);
  1419.     }
  1420.     else
  1421.     {
  1422.         APTR Data;
  1423.  
  1424.         switch(Type)
  1425.         {
  1426.             case PREF_SERIAL:
  1427.  
  1428.                 Data = Config -> SerialConfig;
  1429.                 break;
  1430.  
  1431.             case PREF_MODEM:
  1432.  
  1433.                 Data = Config -> ModemConfig;
  1434.                 break;
  1435.  
  1436.             case PREF_COMMAND:
  1437.  
  1438.                 Data = Config -> CommandConfig;
  1439.                 break;
  1440.  
  1441.             case PREF_SCREEN:
  1442.  
  1443.                 Data = Config -> ScreenConfig;
  1444.                 break;
  1445.  
  1446.             case PREF_TERMINAL:
  1447.  
  1448.                 Data = Config -> TerminalConfig;
  1449.                 break;
  1450.  
  1451.             case PREF_PATH:
  1452.  
  1453.                 Data = Config -> PathConfig;
  1454.                 break;
  1455.  
  1456.             case PREF_MISC:
  1457.  
  1458.                 Data = Config -> MiscConfig;
  1459.                 break;
  1460.  
  1461.             case PREF_CLIP:
  1462.  
  1463.                 Data = Config -> ClipConfig;
  1464.                 break;
  1465.  
  1466.             case PREF_CAPTURE:
  1467.  
  1468.                 Data = Config -> CaptureConfig;
  1469.                 break;
  1470.  
  1471.             case PREF_FILE:
  1472.  
  1473.                 Data = Config -> FileConfig;
  1474.                 break;
  1475.  
  1476.             case PREF_EMULATION:
  1477.  
  1478.                 Data = Config -> EmulationConfig;
  1479.                 break;
  1480.  
  1481.             case PREF_TRANSFER:
  1482.  
  1483.                 Data = Config -> TransferConfig;
  1484.                 break;
  1485.  
  1486.             default:
  1487.  
  1488.                 return(FALSE);
  1489.         }
  1490.  
  1491.         if(!Data)
  1492.         {
  1493.             if(Data = AllocVecPooled(SizeTable[Type - 1],MEMF_ANY | MEMF_CLEAR))
  1494.             {
  1495.                 (*ResetTable[Type - 1])(Data,NULL);
  1496.  
  1497.                 switch(Type)
  1498.                 {
  1499.                     case PREF_SERIAL:
  1500.  
  1501.                         Config -> SerialConfig        = Data;
  1502.                         break;
  1503.  
  1504.                     case PREF_MODEM:
  1505.  
  1506.                         Config -> ModemConfig        = Data;
  1507.                         break;
  1508.  
  1509.                     case PREF_COMMAND:
  1510.  
  1511.                         Config -> CommandConfig        = Data;
  1512.                         break;
  1513.  
  1514.                     case PREF_SCREEN:
  1515.  
  1516.                         Config -> ScreenConfig        = Data;
  1517.                         break;
  1518.  
  1519.                     case PREF_TERMINAL:
  1520.  
  1521.                         Config -> TerminalConfig    = Data;
  1522.                         break;
  1523.  
  1524.                     case PREF_PATH:
  1525.  
  1526.                         Config -> PathConfig        = Data;
  1527.                         break;
  1528.  
  1529.                     case PREF_MISC:
  1530.  
  1531.                         Config -> MiscConfig        = Data;
  1532.                         break;
  1533.  
  1534.                     case PREF_CLIP:
  1535.  
  1536.                         Config -> ClipConfig        = Data;
  1537.                         break;
  1538.  
  1539.                     case PREF_CAPTURE:
  1540.  
  1541.                         Config -> CaptureConfig        = Data;
  1542.                         break;
  1543.  
  1544.                     case PREF_FILE:
  1545.  
  1546.                         Config -> FileConfig        = Data;
  1547.                         break;
  1548.  
  1549.                     case PREF_EMULATION:
  1550.  
  1551.                         Config -> EmulationConfig    = Data;
  1552.                         break;
  1553.  
  1554.                     case PREF_TRANSFER:
  1555.  
  1556.                         Config -> TransferConfig    = Data;
  1557.                         break;
  1558.                 }
  1559.  
  1560.                 return(TRUE);
  1561.             }
  1562.             else
  1563.                 return(FALSE);
  1564.         }
  1565.         else
  1566.             return(TRUE);
  1567.     }
  1568. }
  1569.  
  1570. VOID __regargs
  1571. DeleteConfiguration(struct Configuration *Config)
  1572. {
  1573.     if(Config)
  1574.     {
  1575.         DeleteConfigEntry(Config,PREF_ALL);
  1576.  
  1577.         FreeVecPooled(Config);
  1578.     }
  1579. }
  1580.  
  1581. struct Configuration * __regargs
  1582. CreateConfiguration(BYTE Fill)
  1583. {
  1584.     struct Configuration *Config;
  1585.  
  1586.     if(Config = (struct Configuration *)AllocVecPooled(sizeof(struct Configuration),MEMF_ANY | MEMF_CLEAR))
  1587.     {
  1588.         if(Fill)
  1589.         {
  1590.             if(!CreateConfigEntry(Config,PREF_ALL))
  1591.             {
  1592.                 FreeVecPooled(Config);
  1593.  
  1594.                 return(NULL);
  1595.             }
  1596.         }
  1597.  
  1598.         return(Config);
  1599.     }
  1600.     else
  1601.         return(NULL);
  1602. }
  1603.  
  1604. STATIC BYTE
  1605. WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password)
  1606. {
  1607.     APTR Data;
  1608.  
  1609.     switch(Type)
  1610.     {
  1611.         case PREF_SERIAL:
  1612.  
  1613.             Data = Config -> SerialConfig;
  1614.             break;
  1615.  
  1616.         case PREF_MODEM:
  1617.  
  1618.             Data = Config -> ModemConfig;
  1619.             break;
  1620.  
  1621.         case PREF_COMMAND:
  1622.  
  1623.             Data = Config -> CommandConfig;
  1624.             break;
  1625.  
  1626.         case PREF_SCREEN:
  1627.  
  1628.             Data = Config -> ScreenConfig;
  1629.             break;
  1630.  
  1631.         case PREF_TERMINAL:
  1632.  
  1633.             Data = Config -> TerminalConfig;
  1634.             break;
  1635.  
  1636.         case PREF_PATH:
  1637.  
  1638.             Data = Config -> PathConfig;
  1639.             break;
  1640.  
  1641.         case PREF_MISC:
  1642.  
  1643.             Data = Config -> MiscConfig;
  1644.             break;
  1645.  
  1646.         case PREF_CLIP:
  1647.  
  1648.             Data = Config -> ClipConfig;
  1649.             break;
  1650.  
  1651.         case PREF_CAPTURE:
  1652.  
  1653.             Data = Config -> CaptureConfig;
  1654.             break;
  1655.  
  1656.         case PREF_FILE:
  1657.  
  1658.             Data = Config -> FileConfig;
  1659.             break;
  1660.  
  1661.         case PREF_EMULATION:
  1662.  
  1663.             Data = Config -> EmulationConfig;
  1664.             break;
  1665.  
  1666.         case PREF_TRANSFER:
  1667.  
  1668.             Data = Config -> TransferConfig;
  1669.             break;
  1670.  
  1671.         default:
  1672.  
  1673.             Data = NULL;
  1674.             break;
  1675.     }
  1676.  
  1677.     if(Data)
  1678.     {
  1679.         if(TempBuffer)
  1680.         {
  1681.             Encrypt(Data,SizeTable[Type - 1],TempBuffer,Password,20);
  1682.  
  1683.             Data = TempBuffer;
  1684.         }
  1685.  
  1686.         if(!PushChunk(Handle,0,TypeTable[Type - 1],SizeTable[Type - 1]))
  1687.         {
  1688.             if(WriteChunkRecords(Handle,Data,SizeTable[Type - 1],1) == 1)
  1689.             {
  1690.                 if(!PopChunk(Handle))
  1691.                     return(TRUE);
  1692.             }
  1693.         }
  1694.  
  1695.         return(FALSE);
  1696.     }
  1697.     else
  1698.         return(TRUE);
  1699. }
  1700.  
  1701. STATIC UBYTE
  1702. IsConfigChunk(ULONG ID)
  1703. {
  1704.     UBYTE Type;
  1705.  
  1706.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1707.     {
  1708.         if(ID == TypeTable[Type - 1])
  1709.             return(Type);
  1710.     }
  1711.  
  1712.     return(0);
  1713. }
  1714.  
  1715. STATIC BYTE
  1716. WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password)
  1717. {
  1718.     UBYTE Type;
  1719.  
  1720.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1721.     {
  1722.         if(!WriteConfigChunk(Handle,Config,Type,TempBuffer,Password))
  1723.             return(FALSE);
  1724.     }
  1725.  
  1726.     return(TRUE);
  1727. }
  1728.  
  1729. VOID __regargs
  1730. SaveConfig(struct Configuration *Src,struct Configuration *Dst)
  1731. {
  1732.     if(Dst -> SerialConfig && Src -> SerialConfig)
  1733.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1734.  
  1735.     if(Dst -> ModemConfig && Src -> ModemConfig)
  1736.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1737.  
  1738.     if(Dst -> ScreenConfig && Src -> ScreenConfig)
  1739.     {
  1740.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1741.  
  1742.         FixScreenPens(Dst -> ScreenConfig);
  1743.     }
  1744.  
  1745.     if(Dst -> TerminalConfig && Src -> TerminalConfig)
  1746.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1747.  
  1748.     if(Dst -> EmulationConfig && Src -> EmulationConfig)
  1749.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1750.  
  1751.     if(Dst -> ClipConfig && Src -> ClipConfig)
  1752.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1753.  
  1754.     if(Dst -> CaptureConfig && Src -> CaptureConfig)
  1755.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1756.  
  1757.     if(Dst -> CommandConfig && Src -> CommandConfig)
  1758.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1759.  
  1760.     if(Dst -> MiscConfig && Src -> MiscConfig)
  1761.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1762.  
  1763.     if(Dst -> PathConfig && Src -> PathConfig)
  1764.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1765.  
  1766.     if(Dst -> FileConfig && Src -> FileConfig)
  1767.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1768.  
  1769.     if(Dst -> TransferConfig && Src -> TransferConfig)
  1770.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1771. }
  1772.  
  1773. VOID __regargs
  1774. UpdateConfig(struct Configuration *Src,struct Configuration *Dst)
  1775. {
  1776.     if(Src -> SerialConfig)
  1777.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1778.  
  1779.     if(Src -> ModemConfig)
  1780.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1781.  
  1782.     if(Src -> ScreenConfig)
  1783.     {
  1784.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1785.  
  1786.         FixScreenPens(Dst -> ScreenConfig);
  1787.     }
  1788.  
  1789.     if(Src -> TerminalConfig)
  1790.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1791.  
  1792.     if(Src -> EmulationConfig)
  1793.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1794.  
  1795.     if(Src -> ClipConfig)
  1796.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1797.  
  1798.     if(Src -> CaptureConfig)
  1799.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1800.  
  1801.     if(Src -> CommandConfig)
  1802.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1803.  
  1804.     if(Src -> MiscConfig)
  1805.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1806.  
  1807.     if(Src -> PathConfig)
  1808.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1809.  
  1810.     if(Src -> FileConfig)
  1811.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1812.  
  1813.     if(Src -> TransferConfig)
  1814.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1815. }
  1816.  
  1817. VOID __regargs
  1818. SwapConfig(struct Configuration *Src,struct Configuration *Dst)
  1819. {
  1820.     swmem(Dst -> SerialConfig,    Src -> SerialConfig,    sizeof(struct SerialSettings));
  1821.     swmem(Dst -> ModemConfig,    Src -> ModemConfig,    sizeof(struct ModemSettings));
  1822.     swmem(Dst -> ScreenConfig,    Src -> ScreenConfig,    sizeof(struct ScreenSettings));
  1823.     swmem(Dst -> TerminalConfig,    Src -> TerminalConfig,    sizeof(struct TerminalSettings));
  1824.     swmem(Dst -> EmulationConfig,    Src -> EmulationConfig,    sizeof(struct EmulationSettings));
  1825.     swmem(Dst -> ClipConfig,    Src -> ClipConfig,    sizeof(struct ClipSettings));
  1826.     swmem(Dst -> CaptureConfig,    Src -> CaptureConfig,    sizeof(struct CaptureSettings));
  1827.     swmem(Dst -> CommandConfig,    Src -> CommandConfig,    sizeof(struct CommandSettings));
  1828.     swmem(Dst -> MiscConfig,    Src -> MiscConfig,    sizeof(struct MiscSettings));
  1829.     swmem(Dst -> PathConfig,    Src -> PathConfig,    sizeof(struct PathSettings));
  1830.     swmem(Dst -> FileConfig,    Src -> FileConfig,    sizeof(struct FileSettings));
  1831.     swmem(Dst -> TransferConfig,    Src -> TransferConfig,    sizeof(struct TransferSettings));
  1832. }
  1833.  
  1834.     /* SavePhonebook(STRPTR Name):
  1835.      *
  1836.      *    Save the current phone book to a disk file.
  1837.      */
  1838.  
  1839. BYTE __regargs
  1840. SavePhonebook(STRPTR Name)
  1841. {
  1842.     struct IFFHandle    *Handle;
  1843.     BYTE             Success = FALSE;
  1844.     LONG             Error = 0;
  1845.  
  1846.     if(Phonebook && NumPhoneEntries)
  1847.     {
  1848.         if(Handle = (struct IFFHandle *)AllocIFF())
  1849.         {
  1850.             if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  1851.             {
  1852.                 InitIFFasDOS(Handle);
  1853.  
  1854.                 if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  1855.                 {
  1856.                     if(!(Error = PushChunk(Handle,ID_TERM,ID_CAT,IFFSIZE_UNKNOWN)))
  1857.                     {
  1858.                         if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1859.                         {
  1860.                             if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  1861.                             {
  1862.                                 struct TermInfo TermInfo;
  1863.  
  1864.                                 TermInfo . Version    = CONFIG_FILE_VERSION;
  1865.                                 TermInfo . Revision    = CONFIG_FILE_REVISION;
  1866.  
  1867.                                 if(WriteChunkRecords(Handle,&TermInfo,sizeof(struct TermInfo),1) == 1)
  1868.                                 {
  1869.                                     if(!(Error = PopChunk(Handle)))
  1870.                                     {
  1871.                                         STRPTR TempBuffer = NULL;
  1872.  
  1873.                                         if(PhonePasswordUsed)
  1874.                                         {
  1875.                                             if(!(Error = PushChunk(Handle,0,ID_PSWD,20)))
  1876.                                             {
  1877.                                                 Success = TRUE;
  1878.  
  1879.                                                 if(WriteChunkBytes(Handle,PhonePassword,20) != 20)
  1880.                                                     Success = FALSE;
  1881.  
  1882.                                                 if(PopChunk(Handle))
  1883.                                                     Success = FALSE;
  1884.  
  1885.                                                 if(Success)
  1886.                                                 {
  1887.                                                     LONG Max = sizeof(struct PhoneHeader),Type;
  1888.  
  1889.                                                     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1890.                                                     {
  1891.                                                         if(SizeTable[Type - 1] > Max)
  1892.                                                             Max = SizeTable[Type - 1];
  1893.                                                     }
  1894.  
  1895.                                                     if(!(TempBuffer = AllocVecPooled(Max,MEMF_ANY)))
  1896.                                                     {
  1897.                                                         Error = ERR_NO_MEM;
  1898.  
  1899.                                                         Success = FALSE;
  1900.                                                     }
  1901.                                                 }
  1902.                                             }
  1903.                                         }
  1904.                                         else
  1905.                                             Success = TRUE;
  1906.  
  1907.                                         if(Success)
  1908.                                         {
  1909.                                             Success = FALSE;
  1910.  
  1911.                                             if(!(Error = PushChunk(Handle,0,ID_DIAL,IFFSIZE_UNKNOWN)))
  1912.                                             {
  1913.                                                 if(WriteChunkBytes(Handle,&NumPhoneEntries,sizeof(LONG)) == sizeof(LONG))
  1914.                                                 {
  1915.                                                     if(!(Error = PopChunk(Handle)))
  1916.                                                     {
  1917.                                                         if(!(Error = PopChunk(Handle)))
  1918.                                                         {
  1919.                                                             LONG i;
  1920.  
  1921.                                                             Success = TRUE;
  1922.  
  1923.                                                             for(i = 0 ; Success && i < NumPhoneEntries ; i++)
  1924.                                                             {
  1925.                                                                 Success = FALSE;
  1926.  
  1927.                                                                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1928.                                                                 {
  1929.                                                                     if(!(Error = PushChunk(Handle,0,ID_PHON,sizeof(struct PhoneHeader))))
  1930.                                                                     {
  1931.                                                                         if(TempBuffer)
  1932.                                                                         {
  1933.                                                                             Encrypt((UBYTE *)Phonebook[i] -> Header,sizeof(struct PhoneHeader),TempBuffer,PhonePassword,20);
  1934.  
  1935.                                                                             if(WriteChunkRecords(Handle,TempBuffer,sizeof(struct PhoneHeader),1) == 1)
  1936.                                                                             {
  1937.                                                                                 if(!(Error = PopChunk(Handle)))
  1938.                                                                                 {
  1939.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,TempBuffer,PhonePassword))
  1940.                                                                                     {
  1941.                                                                                         struct TimeDateNode *TimeDateNode;
  1942.  
  1943.                                                                                         Success = TRUE;
  1944.  
  1945.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1946.  
  1947.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1948.                                                                                         {
  1949.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  1950.                                                                                             {
  1951.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1952.                                                                                                 {
  1953.                                                                                                     Error = IoErr();
  1954.  
  1955.                                                                                                     Success = FALSE;
  1956.  
  1957.                                                                                                     break;
  1958.                                                                                                 }
  1959.                                                                                                 else
  1960.                                                                                                 {
  1961.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1962.                                                                                                     {
  1963.                                                                                                         Error = IoErr();
  1964.  
  1965.                                                                                                         Success = FALSE;
  1966.  
  1967.                                                                                                         break;
  1968.                                                                                                     }
  1969.                                                                                                 }
  1970.  
  1971.                                                                                                 if(Success)
  1972.                                                                                                 {
  1973.                                                                                                     if(Error = PopChunk(Handle))
  1974.                                                                                                     {
  1975.                                                                                                         Success = FALSE;
  1976.  
  1977.                                                                                                         break;
  1978.                                                                                                     }
  1979.                                                                                                 }
  1980.  
  1981.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1982.                                                                                             }
  1983.                                                                                         }
  1984.                                                                                     }
  1985.                                                                                     else
  1986.                                                                                     {
  1987.                                                                                         Error = IoErr();
  1988.  
  1989.                                                                                         Success = FALSE;
  1990.                                                                                     }
  1991.                                                                                 }
  1992.                                                                             }
  1993.                                                                             else
  1994.                                                                                 Error = IoErr();
  1995.                                                                         }
  1996.                                                                         else
  1997.                                                                         {
  1998.                                                                             if(WriteChunkRecords(Handle,Phonebook[i] -> Header,sizeof(struct PhoneHeader),1) == 1)
  1999.                                                                             {
  2000.                                                                                 if(!(Error = PopChunk(Handle)))
  2001.                                                                                 {
  2002.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,NULL,NULL))
  2003.                                                                                     {
  2004.                                                                                         struct TimeDateNode *TimeDateNode;
  2005.  
  2006.                                                                                         Success = TRUE;
  2007.  
  2008.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  2009.  
  2010.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  2011.                                                                                         {
  2012.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  2013.                                                                                             {
  2014.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  2015.                                                                                                 {
  2016.                                                                                                     Error = IoErr();
  2017.  
  2018.                                                                                                     Success = FALSE;
  2019.  
  2020.                                                                                                     break;
  2021.                                                                                                 }
  2022.                                                                                                 else
  2023.                                                                                                 {
  2024.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  2025.                                                                                                     {
  2026.                                                                                                         Error = IoErr();
  2027.  
  2028.                                                                                                         Success = FALSE;
  2029.  
  2030.                                                                                                         break;
  2031.                                                                                                     }
  2032.                                                                                                 }
  2033.  
  2034.                                                                                                 if(Success)
  2035.                                                                                                 {
  2036.                                                                                                     if(Error = PopChunk(Handle))
  2037.                                                                                                     {
  2038.                                                                                                         Success = FALSE;
  2039.  
  2040.                                                                                                         break;
  2041.                                                                                                     }
  2042.                                                                                                 }
  2043.  
  2044.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  2045.                                                                                             }
  2046.                                                                                         }
  2047.                                                                                     }
  2048.                                                                                     else
  2049.                                                                                     {
  2050.                                                                                         Success = FALSE;
  2051.  
  2052.                                                                                         Error = IoErr();
  2053.                                                                                     }
  2054.                                                                                 }
  2055.                                                                             }
  2056.                                                                             else
  2057.                                                                                 Error = IoErr();
  2058.                                                                         }
  2059.                                                                     }
  2060.  
  2061.                                                                     if(Success)
  2062.                                                                     {
  2063.                                                                         if(PopChunk(Handle))
  2064.                                                                             Success = FALSE;
  2065.                                                                     }
  2066.                                                                 }
  2067.                                                             }
  2068.                                                         }
  2069.                                                     }
  2070.                                                 }
  2071.                                                 else
  2072.                                                     Error = IoErr();
  2073.                                             }
  2074.                                         }
  2075.  
  2076.                                         if(TempBuffer)
  2077.                                             FreeVecPooled(TempBuffer);
  2078.                                     }
  2079.                                 }
  2080.                                 else
  2081.                                     Error = IoErr();
  2082.                             }
  2083.                         }
  2084.  
  2085.                         if(Success)
  2086.                         {
  2087.                             if(Error = PopChunk(Handle))
  2088.                                 Success = FALSE;
  2089.                         }
  2090.                     }
  2091.  
  2092.                     CloseIFF(Handle);
  2093.                 }
  2094.  
  2095.                 Close(Handle -> iff_Stream);
  2096.             }
  2097.             else
  2098.                 Error = IoErr();
  2099.  
  2100.             FreeIFF(Handle);
  2101.         }
  2102.         else
  2103.             Error = ERR_NO_MEM;
  2104.  
  2105.         if(Success)
  2106.             AddProtection(Name,FIBF_EXECUTE);
  2107.         else
  2108.             DeleteFile(Name);
  2109.     }
  2110.  
  2111.     if(Error)
  2112.         SetIoErr(Error);
  2113.  
  2114.     return(Success);
  2115. }
  2116.  
  2117. STATIC BYTE
  2118. ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password)
  2119. {
  2120.     if(CreateConfigEntry(Config,Type))
  2121.     {
  2122.         APTR Data;
  2123.  
  2124.         switch(Type)
  2125.         {
  2126.             case PREF_SERIAL:
  2127.  
  2128.                 Data = Config -> SerialConfig;
  2129.                 break;
  2130.  
  2131.             case PREF_MODEM:
  2132.  
  2133.                 Data = Config -> ModemConfig;
  2134.                 break;
  2135.  
  2136.             case PREF_COMMAND:
  2137.  
  2138.                 Data = Config -> CommandConfig;
  2139.                 break;
  2140.  
  2141.             case PREF_SCREEN:
  2142.  
  2143.                 Data = Config -> ScreenConfig;
  2144.                 break;
  2145.  
  2146.             case PREF_TERMINAL:
  2147.  
  2148.                 Data = Config -> TerminalConfig;
  2149.                 break;
  2150.  
  2151.             case PREF_PATH:
  2152.  
  2153.                 Data = Config -> PathConfig;
  2154.                 break;
  2155.  
  2156.             case PREF_MISC:
  2157.  
  2158.                 Data = Config -> MiscConfig;
  2159.                 break;
  2160.  
  2161.             case PREF_CLIP:
  2162.  
  2163.                 Data = Config -> ClipConfig;
  2164.                 break;
  2165.  
  2166.             case PREF_CAPTURE:
  2167.  
  2168.                 Data = Config -> CaptureConfig;
  2169.                 break;
  2170.  
  2171.             case PREF_FILE:
  2172.  
  2173.                 Data = Config -> FileConfig;
  2174.                 break;
  2175.  
  2176.             case PREF_EMULATION:
  2177.  
  2178.                 Data = Config -> EmulationConfig;
  2179.                 break;
  2180.  
  2181.             case PREF_TRANSFER:
  2182.  
  2183.                 Data = Config -> TransferConfig;
  2184.                 break;
  2185.         }
  2186.  
  2187.         Len = MIN(SizeTable[Type - 1],Len);
  2188.  
  2189.         if(ReadChunkBytes(Handle,Data,Len) == Len)
  2190.         {
  2191.             if(Password)
  2192.                 Decrypt(Data,Len,Data,Password,20);
  2193.  
  2194.             if(Type == PREF_SCREEN)
  2195.                 FixScreenPens(Data);
  2196.  
  2197.             return(TRUE);
  2198.         }
  2199.     }
  2200.  
  2201.     return(FALSE);
  2202. }
  2203.  
  2204.     /* LoadPhonebook(STRPTR Name):
  2205.      *
  2206.      *    Restore a phone book from a disk file.
  2207.      */
  2208.  
  2209. BYTE __regargs
  2210. LoadPhonebook(STRPTR Name)
  2211. {
  2212.     struct PhoneEntry    **PrivatePhonebook;
  2213.     LONG             PrivatePhoneSize    = 0,
  2214.                  CurrentPhoneSize    = 0,
  2215.                  Count            = 0,
  2216.                  Index            = 0;
  2217.     BYTE             Success        = FALSE,
  2218.                  LastHadTime        = TRUE,
  2219.                  UsePhonePassword    = FALSE,
  2220.                  FirstChunk        = TRUE,
  2221.                  UseOld            = FALSE;
  2222.     struct IFFHandle    *Handle;
  2223.     struct ContextNode    *Chunk;
  2224.     struct TimeDateNode    *TimeDateNode;
  2225.     UBYTE             ConfigChunkType,
  2226.                  PasswordBuffer[20];
  2227.     BYTE             CheckedChunk = FALSE;
  2228.     LONG             Error = 0;
  2229.  
  2230.     if(Handle = AllocIFF())
  2231.     {
  2232.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  2233.         {
  2234.             InitIFFasDOS(Handle);
  2235.  
  2236.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  2237.             {
  2238.                 if(!(Error = StopChunks(Handle,Stops,NUM_STOPS)))
  2239.                 {
  2240.                     struct TermInfo TermInfo;
  2241.  
  2242.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  2243.                     {
  2244.                         Chunk = CurrentChunk(Handle);
  2245.  
  2246.                             /* Is this the first chunk to be read? */
  2247.  
  2248.                         if(!CheckedChunk)
  2249.                         {
  2250.                                 /* The first chunk must be a
  2251.                                  * catalog chunk, or this is
  2252.                                  * not a proper phonebook file.
  2253.                                  */
  2254.  
  2255.                             if(Chunk -> cn_ID != ID_CAT)
  2256.                                 break;
  2257.                             else
  2258.                                 CheckedChunk = TRUE;
  2259.                         }
  2260.  
  2261.                         if(Chunk -> cn_ID == ID_VERS)
  2262.                         {
  2263.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2264.                             {
  2265.                                 if(TermInfo . Version != CONFIG_FILE_VERSION || (TermInfo . Version == CONFIG_FILE_VERSION && TermInfo . Revision > CONFIG_FILE_REVISION))
  2266.                                 {
  2267.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  2268.                                         UseOld = TRUE;
  2269.  
  2270.                                     if(TermInfo . Version != 3)
  2271.                                         break;
  2272.                                 }
  2273.                             }
  2274.                             else
  2275.                             {
  2276.                                 Error = IoErr();
  2277.  
  2278.                                 break;
  2279.                             }
  2280.                         }
  2281.  
  2282.                         if(Chunk -> cn_ID == ID_PSWD)
  2283.                         {
  2284.                             if(ReadChunkBytes(Handle,PasswordBuffer,20) == 20)
  2285.                             {
  2286.                                 if(PhonePasswordUsed)
  2287.                                 {
  2288.                                     if(!memcmp(PhonePassword,PasswordBuffer,20))
  2289.                                     {
  2290.                                         UsePhonePassword = TRUE;
  2291.  
  2292.                                         continue;
  2293.                                     }
  2294.                                 }
  2295.  
  2296.                                 memset(SharedBuffer,0,21);
  2297.  
  2298.                                 if(GetString(FALSE,TRUE,21,LocaleString(MSG_PHONEPANEL_PLEASE_ENTER_PASSWORD_TXT),SharedBuffer))
  2299.                                 {
  2300.                                     UBYTE AnotherBuffer[20];
  2301.  
  2302.                                     Encrypt(SharedBuffer,20,AnotherBuffer,SharedBuffer,strlen(SharedBuffer));
  2303.  
  2304.                                     if(!memcmp(PasswordBuffer,AnotherBuffer,20))
  2305.                                     {
  2306.                                         UsePhonePassword = TRUE;
  2307.  
  2308.                                         continue;
  2309.                                     }
  2310.                                     else
  2311.                                     {
  2312.                                         MyEasyRequest(Window,LocaleString(MSG_TERMPHONE_WRONG_PASSWORD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Name);
  2313.  
  2314.                                         break;
  2315.                                     }
  2316.                                 }
  2317.                                 else
  2318.                                     break;
  2319.                             }
  2320.                             else
  2321.                             {
  2322.                                 Error = IoErr();
  2323.  
  2324.                                 break;
  2325.                             }
  2326.                         }
  2327.  
  2328.                         if(Chunk -> cn_ID == ID_DIAL)
  2329.                         {
  2330.                             if(ReadChunkBytes(Handle,&CurrentPhoneSize,sizeof(LONG)) == sizeof(LONG))
  2331.                             {
  2332.                                 if(!CurrentPhoneSize)
  2333.                                     break;
  2334.                                 else
  2335.                                 {
  2336.                                     if(!(PrivatePhonebook = CreatePhonebook(CurrentPhoneSize,&PrivatePhoneSize,TRUE)))
  2337.                                     {
  2338.                                         Error = ERR_NO_MEM;
  2339.  
  2340.                                         break;
  2341.                                     }
  2342.                                 }
  2343.                             }
  2344.                             else
  2345.                             {
  2346.                                 Error = IoErr();
  2347.  
  2348.                                 break;
  2349.                             }
  2350.                         }
  2351.  
  2352.                         if(Chunk -> cn_ID == ID_PHON)
  2353.                         {
  2354.                             WORD Size = MIN(sizeof(struct PhoneHeader),Chunk -> cn_Size);
  2355.  
  2356.                             if(!CurrentPhoneSize)
  2357.                                 break;
  2358.  
  2359.                             if(!LastHadTime)
  2360.                             {
  2361.                                 if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  2362.                                     AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2363.                             }
  2364.  
  2365.                             if(!FirstChunk)
  2366.                                 Index++;
  2367.                             else
  2368.                                 FirstChunk = FALSE;
  2369.  
  2370.                             if(ReadChunkBytes(Handle,PrivatePhonebook[Index] -> Header,Size) == Size)
  2371.                             {
  2372.                                 if(UsePhonePassword)
  2373.                                     Decrypt((UBYTE *)PrivatePhonebook[Index] -> Header,Size,(UBYTE *)PrivatePhonebook[Index] -> Header,PasswordBuffer,20);
  2374.  
  2375.                                 PrivatePhonebook[Index] -> Count = -1;
  2376.  
  2377.                                 LastHadTime = FALSE;
  2378.  
  2379.                                 Count++;
  2380.                             }
  2381.                             else
  2382.                             {
  2383.                                 Error = IoErr();
  2384.  
  2385.                                 break;
  2386.                             }
  2387.                         }
  2388.  
  2389.                         if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  2390.                         {
  2391.                             if(!CurrentPhoneSize)
  2392.                                 break;
  2393.  
  2394.                             if(UsePhonePassword)
  2395.                             {
  2396.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,PasswordBuffer))
  2397.                                 {
  2398.                                     if(Count)
  2399.                                         CurrentPhoneSize = Count - 1;
  2400.                                     else
  2401.                                         CurrentPhoneSize = 0;
  2402.  
  2403.                                     break;
  2404.                                 }
  2405.                                 else
  2406.                                     FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE,TermInfo . Version,TermInfo . Revision);
  2407.                             }
  2408.                             else
  2409.                             {
  2410.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  2411.                                 {
  2412.                                     if(Count)
  2413.                                         CurrentPhoneSize = Count - 1;
  2414.                                     else
  2415.                                         CurrentPhoneSize = 0;
  2416.  
  2417.                                     break;
  2418.                                 }
  2419.                                 else
  2420.                                     FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE,TermInfo . Version,TermInfo . Revision);
  2421.                             }
  2422.                         }
  2423.  
  2424.                         if(Chunk -> cn_ID == ID_DATE)
  2425.                         {
  2426.                             WORD Count = (Chunk -> cn_Size - sizeof(struct TimeDateHeader)) / sizeof(struct TimeDate);
  2427.  
  2428.                             if(!CurrentPhoneSize)
  2429.                                 break;
  2430.  
  2431.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",Count))
  2432.                             {
  2433.                                 if(ReadChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) == sizeof(struct TimeDateHeader))
  2434.                                 {
  2435.                                     if(ReadChunkRecords(Handle,TimeDateNode -> Table,sizeof(struct TimeDate),Count) == Count)
  2436.                                     {
  2437.                                         AdaptTimeDateNode(TimeDateNode);
  2438.  
  2439.                                         AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2440.  
  2441.                                         LastHadTime = TRUE;
  2442.                                     }
  2443.                                     else
  2444.                                     {
  2445.                                         Error = IoErr();
  2446.  
  2447.                                         FreeTimeDateNode(TimeDateNode);
  2448.                                     }
  2449.                                 }
  2450.                                 else
  2451.                                 {
  2452.                                     Error = IoErr();
  2453.  
  2454.                                     FreeTimeDateNode(TimeDateNode);
  2455.                                 }
  2456.                             }
  2457.                         }
  2458.                     }
  2459.  
  2460.                     if(CurrentPhoneSize)
  2461.                     {
  2462.                         LONG i;
  2463.  
  2464.                         if(!LastHadTime)
  2465.                         {
  2466.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  2467.                                 AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2468.                         }
  2469.  
  2470.                         if(Phonebook)
  2471.                             DeletePhonebook(Phonebook,PhoneSize,TRUE);
  2472.  
  2473.                         Phonebook    = PrivatePhonebook;
  2474.                         PhoneSize    = PrivatePhoneSize;
  2475.                         NumPhoneEntries    = CurrentPhoneSize;
  2476.                         Success        = TRUE;
  2477.  
  2478.                         memcpy(PhonePassword,PasswordBuffer,20);
  2479.                         PhonePasswordUsed = UsePhonePassword;
  2480.  
  2481.                         for(i = NumPhoneEntries ; i < PhoneSize ; i++)
  2482.                         {
  2483.                             if(Phonebook[i])
  2484.                             {
  2485.                                 if(Phonebook[i] -> Config)
  2486.                                     DeleteConfiguration(Phonebook[i] -> Config);
  2487.  
  2488.                                 FreeVecPooled(Phonebook[i]);
  2489.  
  2490.                                 Phonebook[i] = NULL;
  2491.                             }
  2492.                         }
  2493.  
  2494.                         FreeDialList(TRUE);
  2495.  
  2496.                         for(i = 0 ; i < NumPhoneEntries ; i++)
  2497.                             FinalFix(Phonebook[i] -> Config,TRUE,TermInfo . Version,TermInfo . Revision);
  2498.                     }
  2499.                     else
  2500.                     {
  2501.                         if(PrivatePhoneSize)
  2502.                         {
  2503.                             DeletePhonebook(PrivatePhonebook,PrivatePhoneSize,TRUE);
  2504.  
  2505.                             Success = FALSE;
  2506.                         }
  2507.                     }
  2508.                 }
  2509.  
  2510.                 CloseIFF(Handle);
  2511.             }
  2512.  
  2513.             Close(Handle -> iff_Stream);
  2514.         }
  2515.         else
  2516.             Error = IoErr();
  2517.  
  2518.         FreeIFF(Handle);
  2519.     }
  2520.     else
  2521.         Error = ERR_NO_MEM;
  2522.  
  2523.     if(Error)
  2524.         SetIoErr(Error);
  2525.  
  2526.     if(UseOld)
  2527.         return(LoadOldPhonebook(Name));
  2528.     else
  2529.         return(Success);
  2530. }
  2531.  
  2532.     /* WriteConfig(STRPTR Name,struct Configuration *Config):
  2533.      *
  2534.      *    Write the configuration to a file, very much like
  2535.      *    WriteIFFData().
  2536.      */
  2537.  
  2538. BYTE __regargs
  2539. WriteConfig(STRPTR Name,struct Configuration *Config)
  2540. {
  2541.     struct IFFHandle    *Handle;
  2542.     BYTE             Success = FALSE;
  2543.     LONG             Error = 0;
  2544.  
  2545.         /* Allocate a handle. */
  2546.  
  2547.     if(Handle = AllocIFF())
  2548.     {
  2549.             /* Open an output stream. */
  2550.  
  2551.         if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  2552.         {
  2553.                 /* Tell iffparse that this is
  2554.                  * a DOS handle.
  2555.                  */
  2556.  
  2557.             InitIFFasDOS(Handle);
  2558.  
  2559.                 /* Open the handle for writing. */
  2560.  
  2561.             if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  2562.             {
  2563.                     /* Push outmost chunk onto stack. */
  2564.  
  2565.                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  2566.                 {
  2567.                         /* Add a version identifier. */
  2568.  
  2569.                     if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  2570.                     {
  2571.                         struct TermInfo TermInfo;
  2572.  
  2573.                         TermInfo . Version    = CONFIG_FILE_VERSION;
  2574.                         TermInfo . Revision    = CONFIG_FILE_REVISION;
  2575.  
  2576.                             /* Update the other configuration pointer as well. */
  2577.  
  2578.                         Config -> SerialConfig -> LastVersionSaved    = TermVersion;
  2579.                         Config -> SerialConfig -> LastRevisionSaved    = TermRevision;
  2580.  
  2581.                             /* Write the version data. */
  2582.  
  2583.                         if(WriteChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2584.                         {
  2585.                                 /* Pop the version chunk, i.e. write it to the file. */
  2586.  
  2587.                             if(Error = PopChunk(Handle))
  2588.                                 Success = FALSE;
  2589.                             else
  2590.                             {
  2591.                                 if(WriteConfigChunks(Handle,Config,NULL,NULL))
  2592.                                 {
  2593.                                     LONG i;
  2594.  
  2595.                                     Success = TRUE;
  2596.  
  2597.                                     for(i = 0 ; Success && i < WINDOW_COUNT ; i++)
  2598.                                     {
  2599.                                         if(!(Error = PushChunk(Handle,0,ID_WINF,sizeof(struct WindowInfo))))
  2600.                                         {
  2601.                                             if(WriteChunkBytes(Handle,&WindowInfoTable[i],sizeof(struct WindowInfo)) == sizeof(struct WindowInfo))
  2602.                                             {
  2603.                                                 if(Error = PopChunk(Handle))
  2604.                                                     Success = FALSE;
  2605.                                             }
  2606.                                             else
  2607.                                             {
  2608.                                                 Error = IoErr();
  2609.  
  2610.                                                 Success = FALSE;
  2611.                                             }
  2612.                                         }
  2613.                                         else
  2614.                                             Success = FALSE;
  2615.                                     }
  2616.                                 }
  2617.                             }
  2618.                         }
  2619.                         else
  2620.                         {
  2621.                             Error = IoErr();
  2622.  
  2623.                             Success = FALSE;
  2624.                         }
  2625.                     }
  2626.  
  2627.                         /* Seems that we're done, now try to pop the FORM chunk
  2628.                          * and return.
  2629.                          */
  2630.  
  2631.                     if(Success)
  2632.                     {
  2633.                         if(Error = PopChunk(Handle))
  2634.                             Success = FALSE;
  2635.                     }
  2636.                 }
  2637.  
  2638.                     /* Close the handle (flush any pending data). */
  2639.  
  2640.                 CloseIFF(Handle);
  2641.             }
  2642.  
  2643.                 /* Close the DOS handle itself. */
  2644.  
  2645.             Close(Handle -> iff_Stream);
  2646.         }
  2647.         else
  2648.             Error = IoErr();
  2649.  
  2650.             /* And free the IFF handle. */
  2651.  
  2652.         FreeIFF(Handle);
  2653.     }
  2654.     else
  2655.         Error = ERR_NO_MEM;
  2656.  
  2657.     if(Success)
  2658.         AddProtection(Name,FIBF_EXECUTE);
  2659.  
  2660.     return(Success);
  2661. }
  2662.  
  2663.     /* ReadConfig(STRPTR Name,struct Configuration *Config):
  2664.      *
  2665.      *    Read the configuration file, very much the same as ReadIFFData().
  2666.      */
  2667.  
  2668. BYTE __regargs
  2669. ReadConfig(STRPTR Name,struct Configuration *Config)
  2670. {
  2671.     struct IFFHandle    *Handle;
  2672.     BYTE             Success    = FALSE,
  2673.                  UseOld        = FALSE;
  2674.     struct ContextNode    *Chunk;
  2675.     UBYTE             ConfigChunkType;
  2676.     LONG             Error = 0;
  2677.  
  2678.     if(Handle = AllocIFF())
  2679.     {
  2680.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  2681.         {
  2682.             InitIFFasDOS(Handle);
  2683.  
  2684.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  2685.             {
  2686.                 if(!StopChunks(Handle,Stops,NUM_STOPS))
  2687.                 {
  2688.                     struct TermInfo TermInfo;
  2689.  
  2690.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  2691.                     {
  2692.                         Chunk = CurrentChunk(Handle);
  2693.  
  2694.                             /* Oops! Some is trying to
  2695.                              * use the phone book file as
  2696.                              * a configuration file.
  2697.                              */
  2698.  
  2699.                         if(Chunk -> cn_ID == ID_CAT)
  2700.                         {
  2701.                             Success = FALSE;
  2702.  
  2703.                             break;
  2704.                         }
  2705.  
  2706.                         if(Chunk -> cn_ID == ID_VERS)
  2707.                         {
  2708.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2709.                             {
  2710.                                 if(TermInfo . Version != CONFIG_FILE_VERSION || (TermInfo . Version == CONFIG_FILE_VERSION && TermInfo . Revision > CONFIG_FILE_REVISION))
  2711.                                 {
  2712.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  2713.                                         UseOld = TRUE;
  2714.  
  2715.                                     if(TermInfo . Version != 3)
  2716.                                         break;
  2717.                                 }
  2718.                             }
  2719.                             else
  2720.                             {
  2721.                                 Error = IoErr();
  2722.  
  2723.                                 break;
  2724.                             }
  2725.                         }
  2726.  
  2727.                         if(Chunk -> cn_ID == ID_WINF)
  2728.                         {
  2729.                             struct WindowInfo Info;
  2730.  
  2731.                             if(ReadChunkBytes(Handle,&Info,sizeof(Info)) == sizeof(Info))
  2732.                             {
  2733.                                 Success = TRUE;
  2734.  
  2735.                                 ReplaceWindowInfo(&Info);
  2736.                             }
  2737.                             else
  2738.                             {
  2739.                                 Error = IoErr();
  2740.  
  2741.                                 Success = FALSE;
  2742.                                 break;
  2743.                             }
  2744.                         }
  2745.                         else
  2746.                         {
  2747.                             if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  2748.                             {
  2749.                                 if(ReadConfigChunk(Handle,Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  2750.                                 {
  2751.                                     FixOldConfig(Config,ConfigChunkType,FALSE,TermInfo . Version,TermInfo . Revision);
  2752.  
  2753.                                     Success = TRUE;
  2754.                                 }
  2755.                                 else
  2756.                                 {
  2757.                                     Error = IoErr();
  2758.  
  2759.                                     Success = FALSE;
  2760.  
  2761.                                     break;
  2762.                                 }
  2763.                             }
  2764.                         }
  2765.                     }
  2766.  
  2767.                     if(Success)
  2768.                         FinalFix(Config,FALSE,TermInfo . Version,TermInfo . Revision);
  2769.                 }
  2770.  
  2771.                 CloseIFF(Handle);
  2772.             }
  2773.  
  2774.             Close(Handle -> iff_Stream);
  2775.         }
  2776.  
  2777.         FreeIFF(Handle);
  2778.     }
  2779.     else
  2780.         Error = IoErr();
  2781.  
  2782.     if(Error)
  2783.         SetIoErr(Error);
  2784.  
  2785.     if(UseOld)
  2786.         return(ReadOldConfig(Name,Config));
  2787.     else
  2788.         return(Success);
  2789. }
  2790.